import { Request } from './request';
import type { CreateRequestConfig } from './types';

// 环境URL配置 - 极简版
const LOCAL_API = 'http://localhost:8000';
const DEV_API = 'http://118.145.203.157:18088';
const PROD_API = 'https://luguodepanghu.online/api';

// 环境类型
export type ApiEnv = 'local' | 'dev' | 'prod';

// 切换环境 (开发时直接修改这一行)
const CURRENT_ENV: ApiEnv = 'prod';

// 环境URL映射
const API_URLS = {
    local: LOCAL_API,
    dev: DEV_API,
    prod: PROD_API
};

// API 基础URL
const BASE_URL = API_URLS[CURRENT_ENV];

// API路径常量
export const API_PATH = {
    ARTICLE: {
        LIST: '/v1/generate/wechat/articles',
        DETAIL: (id: string) => `/v1/generate/wechat/articles/${id}`,
        CREATE: '/v1/generate/wechat/article',
        UPDATE: (id: string) => `/v1/generate/wechat/articles/${id}`,
        DELETE: (id: string) => `/v1/generate/wechat/articles/${id}`,
        ARTICLE_DETAIL: '/v1/generate/wechat/article-details',
        START_GENERATION: '/v1/generate/wechat/start-generation',
        REGENERATE_COVER: '/v1/generate/wechat/regenerate-cover',
        RETRY_FAILED: '/v1/generate/wechat/retry-failed',
        REGENERATE_TITLE: '/v1/generate/wechat/regenerate-title',
        UPDATE_USAGE_STATUS: '/v1/generate/wechat/update-usage-status',
        UPDATE_COVER: '/v1/generate/wechat/update-cover',
    },
    ARTICLE_CENTER: {
        CREATE: '/v1/article/create',
        LIST: '/v1/article/list',
        DETAIL: (id: string) => `/v1/article/${id}`,
        DERIVATIVE: '/v1/article/derivative',
        ILLUSTRATION: (id: string) => `/v1/illustration/article/${id}`,
        GENERATE_IMAGE: '/v1/article/generate-image',
        UPDATE_CONTENT: '/v1/illustration/update-content',
        REGENERATE_DESCRIPTION: '/v1/illustration/regenerate-description',
        REGENERATE_IMAGE: '/v1/illustration/regenerate-image',
        UPDATE_DESCRIPTION: '/v1/illustration/update-description',
    },
    MATERIAL: {
        CREATE: '/v1/material/wechat/article',
        LIST: '/v1/material/list',
        SOURCES: '/v1/material/sources',
        DETAIL: '/v1/material/detail',
        RETRY: '/v1/material/retry',
        DELETE: '/v1/material/delete'
    },
    AUTH: {
        LOGIN: '/v1/auth/login',
        ME: '/v1/auth/me',
        REGISTER: '/v1/auth/register',
        USERS: '/v1/auth/users',
    },
    USER: {
        LOGIN: '/v1/user/login',
        LOGOUT: '/v1/user/logout',
        PROFILE: '/v1/user/profile',
    },
    SYSTEM: {
        CONFIG: '/v1/system/config',
        STATUS: '/v1/system/status',
    }
};

// HTTP请求实例配置
const config: CreateRequestConfig = {
    baseURL: BASE_URL,
    timeout: 10000,
    headers: {
        'Content-Type': 'application/json',
    },
    requestOptions: {
        showLoading: true,
        showError: true,
    },
};

// 创建请求实例
export const http = new Request(config);

// 导出类型
export type { ResponseData, SingleResponse, ListResponse, EmptyResponse, PaginationMeta } from './types'; 